package com.yidu.boss.sys.service.impl;


import com.yidu.boss.sys.dao.BrokerMapper;
import com.yidu.boss.sys.domain.Broker;
import com.yidu.boss.sys.domain.BrokerExample;
import com.yidu.boss.sys.service.BrokerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @program: fund_management_system
 * @ClassName BrokerServiceImpl
 * @author: Zc
 * @create: 2019-11-26 08:59
 **/
@Service
public class BrokerServiceImpl implements BrokerService {

    @Resource
    BrokerMapper brokerMapper;

    @Override
    public List<Broker> selectAll() {
        return brokerMapper.selectByExample(null);
    }

    @Override
    public int update(Broker broker) {
        return brokerMapper.updateByPrimaryKeySelective(broker);
    }

    @Override
    public int add(Broker broker) {
        broker.setBrokerid(UUID.randomUUID().toString().replace("-","").substring(0,6));
        System.err.println(broker);
        return brokerMapper.insert(broker);
    }

    @Override
    public int delete(String id) {
        return brokerMapper.deleteByPrimaryKey(id);
    }


    @Override
    public List<Broker> selectLike(String Keyword) {
        BrokerExample brokerExample = new BrokerExample();
        brokerExample.or().andBrokeridLike("%"+Keyword+"%");
        brokerExample.or().andBrokernameLike("%"+Keyword+"%");
        brokerExample.or().andDecsLike("%"+Keyword+"%");
        brokerExample.or().andSeatidLike("%"+Keyword+"%");
        brokerExample.or().andSeatnameLike("%"+Keyword+"%");
        return brokerMapper.selectByExample(brokerExample);
    }
}
